package com.base.object;


import java.util.Objects;

/**
 * @author innocent
 * @date 2019/2/21 18:51
 */
public class EqualsDemo {
    /**
     * Object类的toString()方法和重写toString（）方法
     */
    public void test1() {
        Person person = new Person();
        Animal animal = new Animal();

        person.setUsername("mike");
        System.out.println(person.equals(animal));
    }
}


class Person {
    private String username;
    private String password;

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }

    public void run() {
        System.out.println("跑。。。");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Person person = (Person) o;
        return Objects.equals(username, person.username) &&
                Objects.equals(password, person.password);
    }

    @Override
    public int hashCode() {

        return Objects.hash(username, password);
    }
}

class Animal{
    private String name;
    private int age;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void eat() {
        System.out.println("吃。。。");
    }
}